/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.common.constant.knowledge;


import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 安全威胁类型
 * @author zpy
 * @version 1.0.0
 */
public enum ThreatType {
    /**物理和环境**/
    PHY_ENV("TP","物理和环境"),
    /**网络和通信**/
    NET_COMMUNICATION("TN","网络和通信"),
    /**设备和计算**/
    DEVICE_COMPUTE("TD","设备和计算"),
    /**应用和数据**/
    APP_DATA("TA","应用和数据"),
    /**密钥管理和安全管理**/
    MANAGE("TK","密钥管理和安全管理");

    private final String code;
    private final String name;

    ThreatType(String code,String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }
    public String getName(){
        return this.name;
    }

    public static List<String> findThreatTypeNames(){
        return Stream.of(ThreatType.values())
                .map(ThreatType::getName)
                .collect(Collectors.toList());
    }

    public static ThreatType fromName(String name){
        ThreatType data = null;
        for(ThreatType tt : ThreatType.values()){
            if(StringUtils.equals(tt.name,name)){
                data = tt;
                break;
            }
        }
        return data;
    }

}